﻿$ErrorState = 2
$ErrorMessage = ""
$Trace = ""
$Value = ""
$Error.Clear()

$virstoNamespace = "root\virtualization\storage"
$diskName = '%DISKNAME%'
$Diskid = ''
           
try {
            
    $Trace += 'Connecting to Virsto...  \n'

    $vdisk1 = gwmi -query "select * from Virsto_VSVDisk where name='$diskName'" -namespace $virstoNamespace
    if ($vdisk1 -eq $null) {
    $ErrorState = 1
    $Trace += 'Virsto Disk not exists...  \n'
    }
    else
    {
    $ErrorState = 0
    $Trace += 'Virsto Disk exists...  \n'
    $vdisk1.Delete()
    $Trace += 'Virsto Disk deleted...  \n'
    }
}
catch {
    $ErrorState = 2
    $ErrorMessage = $error[0].Exception.ToString()
}
Finally {
    $Trace += 'ErrorState:  ' + $ErrorState + ' \n'
    $Trace += 'ErrorMessage: ' + $ErrorMessage + ' \n'
}
            
$Results = @($ErrorState, $ErrorMessage, $Trace, $Diskid) 
Return $Results